package fun.werfamily.wf.goods.core.api;

import fun.werfamily.wf.base.annotation.MustLogin;
import fun.werfamily.wf.base.vo.PageInfo;
import fun.werfamily.wf.base.vo.Result;
import fun.werfamily.wf.goods.core.domain.dto.request.GoodsListReqDTO;
import fun.werfamily.wf.goods.core.domain.dto.request.GoodsSkuDetailReqDTO;
import fun.werfamily.wf.goods.core.domain.dto.response.GoodsSkuDTO;
import fun.werfamily.wf.goods.core.domain.dto.response.GoodsSpuDTO;
import fun.werfamily.wf.goods.core.domain.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Mr.WenMing Zhang
 * @Date: 2022-08-19 23:12
 * @Description:
 */
@Api(tags = "商品模块")
@RequestMapping("/open/goods")
@RestController
@Slf4j
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @ApiOperation("商品列表")
    @PostMapping("/list")
    @MustLogin(value = false)
    public Result<PageInfo<GoodsSpuDTO>> goodsList(@RequestBody GoodsListReqDTO goodsListReqDTO){
        log.info("商品列表列表入参,[/api/open/goods/list],req={}", goodsListReqDTO);
        return Result.success(goodsService.goodsList(goodsListReqDTO));
    }

    @ApiOperation("商品spu详情")
    @GetMapping("/spu/detail")
    @MustLogin(value = false)
    public Result<GoodsSpuDTO> goodsSpuDetail(@RequestParam("spuCode") String spuCode){
        log.info("商品spu详情入参,[/api/open/goods/spu/detail],req={}", spuCode);
        return Result.success(goodsService.goodsSpuDetail(spuCode));
    }

    @ApiOperation("商品sku详情")
    @PostMapping("/sku/detail")
    @MustLogin(value = false)
    public Result<List<GoodsSkuDTO>> goodsSkuDetail(@RequestBody GoodsSkuDetailReqDTO goodsSkuDetailReqDTO){
        // TODO 商品主图 附件
        return Result.success(goodsService.goodsSkuDetail(goodsSkuDetailReqDTO));
    }
}
